package Server4;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    private Socket socket;
    private Client(){
        try {
            System.out.println("正在链接");
            socket=new Socket("localhost",8088);//老板ip：176.130.21.37  毛孔ip：176.130.21.28
            System.out.println("链接成功" );
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private void start(){
        try(OutputStream ops=socket.getOutputStream()){
            OutputStreamWriter osw=new OutputStreamWriter(ops,"UTF-8");
            BufferedWriter bw=new BufferedWriter(osw);
            PrintWriter pw=new PrintWriter(bw,true);

            InputStream is=socket.getInputStream();
            InputStreamReader isr=new InputStreamReader(is,"UTF-8");
            BufferedReader br=new BufferedReader(isr);


            Scanner sc=new Scanner(System.in);
            while (true){
                System.out.println("输入0退出");
                String line=sc.nextLine();
                if ("0".equals(line)){
                    break;
                }
                pw.println(line);

                line=br.readLine();
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Client client=new Client();
        client.start();
    }


}
